//文章分类页加载文章列表数据
const db = require("../lib/db");
function classifyArticle(values){
    return new Promise((resolve , reject) => {
        let sql = "select * from essay where classify = '" + values + "'";
        // console.log(sql)
        db.querySql(sql).then(data => {
            if(data.length == 0){ 
                // 返回状态码
                resolve(400)
            }else{
                let arr = data 
                let arr2 = []
                arr.map(element => {
                    arr2.push({
                        _id : Buffer.from(String(element._id)).toString("base64"), 
                        title : element.title ,
                        content : element.content ,
                        time : element.time ,
                        author : element.author ,
                        authorId : Buffer.from(String(element.authorId)).toString("base64"),
                        classify : element.classify ,
                        __v : 0
                    })
                })
                console.log(arr2)
                resolve(arr2)
            }
        })
    })
}
module.exports = classifyArticle
